import ClientMessageHandlerLoader from "@runtime/generate/handler/ClientMessageHandlerLoader";
import ClientRequestHandlerLoader from "@runtime/generate/handler/ClientRequestHandlerLoader";
import ServerMessageHandlerLoader from "@runtime/generate/handler/ServerMessageHandlerLoader";
import ServerRequestHandlerLoader from "@runtime/generate/handler/ServerRequestHandlerLoader";

/**
 * 消息分发组件
 */
export default class MessageDispatcherComponent {
    private static instance: MessageDispatcherComponent = new MessageDispatcherComponent();
    /**
     * 消息分发组件
     */
    public static get Default(): MessageDispatcherComponent {
        return this.instance;
    }

    constructor() {
        window.addEventListener('unload', this.Dispose.bind(this));
    }

    Dispose() {
        window.removeEventListener('unload', this.Dispose);
    }

    public Register(): void {
        ClientMessageHandlerLoader.Default.Load();
        ClientRequestHandlerLoader.Default.Load();
        ServerMessageHandlerLoader.Default.Load();
        ServerRequestHandlerLoader.Default.Load();
    }
}